<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <com1></com1>
      <com2></com2>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
      // 组件复用
      var myMixin = {
        methods:{
          fn(){
            alert(1)
          }
        }
      }
      Vue.component('com1',{
        template:`
          <div @click="fn">组件1</div>
        `,
        mixins:[myMixin]
      })
      Vue.component('com2',{
        template:`:[myMixin]
          <div @click="fn">组件2</div>
        `,
        mixins:[myMixin]
      })
      var vm = new Vue({
        el: '#app',
        data: {},
        methods: {}
      })
    </script>
  </body>
</html>
